using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using Arch.Aspects;
using Arch.Model;
namespace Arch.Samples.Model
{
    [Order("Name")]
    [DataContract(IsReference = true),KnownType(typeof(SubCategory)),KnownType(typeof(GlobalCategory))]
    public partial class Category : Entity<int>
    {
        [DataMember]
        [
            Required, 
            StringLength(30), 
            CustomValidation(typeof(Category), "ValidateName"),
        ]
        public virtual string Name { get; set; }


        public override string ToString()
        {
            return Name;
        }

        public static ValidationResult ValidateName(string name)
        {
            if (string.Compare(name, "category", true) <= 0)
                return new ValidationResult("Category Name cannot be \"category\"", new string[] { "Name" });

            return ValidationResult.Success;
        }
    }
}
